package com.example.helloworld3;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {
    private static final String TAG = "ooo2---->";


    @Override
    public void onBackPressed() {
        Log.d("ooo2--->", "返回按钮！！！");
        Intent intent = new Intent();
        intent.putExtra("extra_data","你好我是返回数据！onBackPressed");
        setResult(RESULT_OK,intent);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        // 获取意图传递过来的数据
        /*Intent intent = getIntent();
        String data = intent.getStringExtra("extra_data");
        Log.d("SecondActivity", data);
        Toast.makeText(this, data, Toast.LENGTH_LONG).show();*/
        Log.d(TAG, "onCreate: "+getTaskId());
        Button button2 = (Button) findViewById(R.id.button_2);
        button2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                /*Toast.makeText(Main2Activity.this, "你点击了我" + System.currentTimeMillis(), Toast.LENGTH_LONG).show();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // 打开一个网页
                intent.setData(Uri.parse("http://www.baidu.com"));
                startActivity(intent);*/

                /**
                 * 携带数据并返回上一个页面
                 */
               /* Intent intent = new Intent();
                intent.putExtra("extra_data","你好我是返回数据！");
                setResult(RESULT_OK,intent);
                finish();*/

                Intent intent = new Intent(Main2Activity.this,ThirdActivity.class);
                startActivity(intent);
            }
        });
    }
}
